<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        function get(url, callback) {
            var xhr = new XMLHttpRequest();
            // 请求加载成功之后的回调函数
            xhr.onload = function () {
                callback(xhr.responseText);
            }
            xhr.open('get', url, true);
            xhr.send();
        }

        get('data.json', function(responseText) {
            console.log(responseText);
        })
    </script>
</body>

</html>